﻿// Fill out your copyright notice in the Description page of Project Settings.


#include "HUD/HealthComponent.h"
#include "HUD/HealthBar.h"
#include "Components/ProgressBar.h"

void UHealthComponent::SetHealthPercent(float Percent)
{
	if (Enemy_HealthBarWidget == nullptr) {
		//class UHealthBar* Enemy_HealthBarWidget = Cast<UHealthBar>(GetUserWidgetObject());
		//多声明了
		//返回的是当前 ​​UUserWidget 对象本身（即 this所代表的对象）的基类指针
		Enemy_HealthBarWidget = Cast<UHealthBar>(GetUserWidgetObject());
	}

	if (Enemy_HealthBarWidget && Enemy_HealthBarWidget->HealthBar) {
		Enemy_HealthBarWidget->HealthBar->SetPercent(Percent);
	}
}
